import {Plugin} from '../extend';
import {XyzaColor} from '../type';
import {parseXyza, rgbaToXyza, roundXyza} from '../color/model/xyz';

declare module '../color' {
    interface Color {
        toXyz(): XyzaColor;
    }
}

/**
 * A plugin adding support for CIE XYZ colorspace.
 * Wikipedia: https://en.wikipedia.org/wiki/CIE_1931_color_space
 * Helpful article: https://www.sttmedia.com/colormodel-xyz
 */
const xyzPlugin: Plugin = (ColorClass, parsers): void => {
    ColorClass.prototype.toXyz = function() {
        return roundXyza(rgbaToXyza(this.rgba));
    };

    parsers.object.push([parseXyza, 'xyz']);
};

export default xyzPlugin;
